<template>
  <div class="app-container">
    <div class="filter-container">
      <el-select v-model="listQuery.serverId" class="filter-item" filterable clearable placeholder="选择区服">
        <el-option v-for="item in serverList" :key="item.sid" :label="item.name+'('+item.sid+')'" :value="item.sid"></el-option>
      </el-select>
      <el-select v-model="listQuery.item_id" class="filter-item" style="width: 130px;" clearable :loading="listLoading" placeholder="选择道具">
        <el-option v-for="item in cfg_items" :key="item.item_id" :label="item.item_name" :value="item.item_id"></el-option>
      </el-select>
      <statisSearchBar :show-channel="false" :show-server="false" :start-date="listQuery.startDate" :end-date="listQuery.endDate" @transferFilter="handleFilter" />
    </div>
    <el-table v-loading="listLoading" :data="list" class="mt-10" border height="710">
      <el-table-column label="序号" prop="index" width="110px" align="center"></el-table-column>
      <el-table-column label="服务器" prop="s_name" width="170px" align="center"></el-table-column>
      <el-table-column label="角色ID" prop="id" width="170px" align="center"></el-table-column>
      <el-table-column label="角色名" prop="name" width="170px" align="center"></el-table-column>
      <el-table-column label="等级" prop="lv" width="98px" align="center"></el-table-column>
      <el-table-column label="VIP" prop="vip_level" width="98px" align="center"></el-table-column>
      <el-table-column label="战力" prop="power" width="170px" align="center"></el-table-column>
      <el-table-column label="消耗" prop="amount" width="300px" align="center"></el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
import StatisSearchBar from '@/components/StatisSearchBar'
import { getItemStaticActorRank, getCfgStItemList } from '@/api/statis'
import { getServerList } from '@/api/ops'
import Pagination from '@/components/Pagination'
const defaultSearchForm = {
  item_id: 17
}
export default {
  name: 'ConsumeActor',
  components: { StatisSearchBar, Pagination },
  data() {
    return {
      list: [],
      listLoading: false,
      cfg_items: [],
      serverList: [],
      total: 0,
      listQuery: {
        startDate: new Date(Date.now() - 86400000 * 10),
        endDate: new Date(),
        serverId: '',
        page: 1,
        limit: 200,
        ...defaultSearchForm
      }
    }
  },
  created() {
    this.getCfgStItemList()
    this.getServerList()
    this.getList()
  },
  methods: {
    handleFilter(query) {
      this.listQuery = { ...defaultSearchForm, ...this.listQuery, ...query }
      this.getList()
    },
    async getList() {
      this.listLoading = true
      const res = await getItemStaticActorRank(Object.assign(this.listQuery, { log_type: 8 }))
      this.listLoading = false
      this.list = res.data.items
      this.total = res.data.total
    },
    async getServerList(params) {
      const query = params
      const res = await getServerList(query)
      this.serverList = res.data.items
      this.loading = false
    },
    async getCfgStItemList() {
      const res = await getCfgStItemList()
      this.cfg_items = res.data.list
    }
  }
}
</script>
